//获得站点信息
function getIndustryInfo(){
    var tbody=window.document.getElementById("industry_data");
    $.ajax({
        url:"../../industry/all",
        type:"GET",
        dataType:"json",
        success:function(data){
            console.log(data);
            if(data.code==0){
                var str="";
                var tdata=data.object;
                for( i in tdata){
                    var j = parseInt(i)+1;
                    str +="<tr>"+"" +
                        "<td height=\"20\" bgcolor=\"#FFFFFF\"><div align=\"center\"><span class=\"STYLE1\">"+ j +"</td>" +
                        "<td height=\"20\" bgcolor=\"#FFFFFF\"><div align=\"center\"><span class=\"STYLE1\">"+tdata[i].name+"</td>" +
                        "<td height=\"20\" bgcolor=\"#FFFFFF\"><div align=\"center\"><span class=\"STYLE1\">" + convertFormatToString(tdata[i].qualifications) + "</td>"+
                        "<td height=\"20\" bgcolor=\"#FFFFFF\"><div align=\"center\"><span class=\"STYLE1\">" +
                        "<input type='button' value='编辑' id='edit_button'+" + tdata[i].id +"/>" +
                        "<input type='button' value='删除' id='del_button'+" + tdata[i].id + " onclick='deleteButtonClick( " + tdata[i].id + ")'" +"/></span></td></tr>";
                }
                tbody.innerHTML =str;
            }
        },
        error:function(){
            alert("search fails！");
        }
    });
}

function addIndustryTrUnVisible() {
    document.getElementById("_add_industry_tbody").style.visibility = "hidden";
}



function convertFormatToString(list) {
    var str = "";
    for ( var i = 0; i < list.length; i++){
        str += list[i];
        str += "; "
    }
    return str;
}

function addButtonClick() {
    document.getElementById("_add_industry_tbody").style.visibility = "visible";
}

function cancelAddButtonClick() {
    document.getElementById("_add_industry_tbody").style.visibility = "hidden";
}

function addSubmitButtonClick() {
    var fdata = $("#industries_form").serialize();
    $.param(fdata);
    $.ajax({
        url:"../../industry/new",
        type:"POST",
        data:fdata,
        async: false,
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        dataType:"json",
        success:function(result){
            if(result.code==0){
                alert(result.message);
                location.href="./industry.html";
            }else if(result.code==1){
                alert(result.message);
            }
        }
    });
}

//      删除已选设备
function deleteButtonClick(id){
    var fdata = $("#industries_form").serialize();
    $.param(fdata);
    $.ajax({
        url:"../../industry/deletion/" + id,
        type:"GET",
        async: false,
        contentType:"application/x-www-form-urlencoded; charset=utf-8",
        dataType:"json",
        success:function(result){
            if(result.code==0){
                alert(result.message);
                location.href="./industry.html";
            }else if(result.code==1){
                alert(result.message);
            }
        }
    });

}
